package com.campus.web.controller;


import com.campus.app.service.ClasssService;
import com.campus.app.service.impl.FunctionServerImpl;
import com.campus.commons.entity.Class;
import com.campus.commons.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 班级表 前端控制器
 * </p>
 *
 * @author Rin
 * @since 2020-12-24
 */
@RestController
@RequestMapping("/_class")
public class ClassController {
    @Autowired
    private ClasssService classsService;

    /**
     * 判断教室是否存在
     *
     * @return
     */
    @RequestMapping("/exitClass")
    public int exitClass(String className) {
         FunctionServerImpl.init();
        return FunctionServerImpl.classes.get(className.toUpperCase());
    }


    /**
     * 获取全部班级信息
     * @author 一行琉璃
     * @param page
     * @param limit
     * @return
     */
    @PostMapping("/all")
    public Result<List<Class>>getall(int page ,int limit){
        Result<List<Class>> alls = classsService.getAlls(page, limit);

        return alls;
    }

    @PostMapping("/wxAll")
    public Result getAllClass() {
        return classsService.getAllClass();
    }
    /**
     * 通过id删除班级
     * @author 一行琉璃
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public Result del(int id){
        Result result = classsService.deleteClass(id);
        return result;
    }

    @PostMapping("/compoundQuery")
    public Result<List<Class>> getAllBy(String begin, String end, int page, int limit ,Class c) {

        Result<List<Class>> allBy = classsService.getAllBy(begin, end, page, limit, c);

        return allBy;
    }
    @PostMapping("/update")
    public Result upd(Class c) {
        String date = null;
        Result result = classsService.update_xml(c);
        System.out.println(result);
        return result;
    }
    @PostMapping("/add")
    public Result add(Class c) {
        Result result = classsService.addClass(c);
        return result;
    }

    @ApiOperation(value = "获取老师所带的班级")
    @PostMapping("/byTeacher")
    public Result getClassByTheacherId(Integer teacherId) {
        return classsService.getClassByTeacherId(teacherId);
    }
    /**@Author 琪亚娜
     * 根据班级id 获取班级
     * @param id
     * @return
     */
    @PostMapping("/get")
    public Class getClass( Integer id) {
        return Class.classes.get(id);

    }
}

